Option Strict On
Option Explicit On

Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Drawing

''' <summary>
''' The ChartSpaceWrapper control places an &lt;object&gt; tag in
''' the resulting HTML, with the classid for the OWC 11.0 
''' ChartSpace component. Properties of the class are rendered
''' as properties of the ActiveX control.
''' </summary>
''' <remarks>
''' The class renders the <code>object</code> tag within a
''' <code>div</code> tag, which is decorated with the class id
''' <code>"OWCNetWrapperChartSpace"</code>. This can be used to
''' style the elements inside the generated Chart.
''' </remarks>
Partial Public Class ChartSpaceWrapper
    Inherits Control
#Region "Shared Members"
    Public Shared ReadOnly Property ClassId() As String
        Get
            Return "clsid:0002E55D-0000-0000-C000-000000000046"
        End Get
    End Property
#End Region
    Private Sub RenderRunTimeUI(ByVal writer As System.Web.UI.HtmlTextWriter)
        With writer
            ' Render outer DIV, with CSS class "OWCNetWrapperChartSpace"
            .AddAttribute(HtmlTextWriterAttribute.Class, "OWCNetWrapperChartSpace")
            .RenderBeginTag(HtmlTextWriterTag.Div)

            ' Render
            '   <object classid="clsid:0002E55A-0000-0000-C000-000000000046" id="PivotTable1">
            .AddAttribute("classid", ClassId)
            .AddAttribute(HtmlTextWriterAttribute.Id, Me.ClientID)
            .RenderBeginTag(HtmlTextWriterTag.Object)

            ' Write the <param> tags
            WriteAllProperties(writer)
            .WriteLine()

            ' Render the "alternate HTML"
            .RenderBeginTag(HtmlTextWriterTag.Span)
            .Write("Your browser does not support ActiveX controls.")
            .RenderEndTag()

            ' Render </object>
            .RenderEndTag()

            ' Render </div>
            .RenderEndTag()
        End With
    End Sub
    Private Sub RenderDesignTimeUI(ByVal writer As System.Web.UI.HtmlTextWriter)
        With writer
            .AddStyleAttribute(HtmlTextWriterStyle.FontFamily, "Arial, Helvetica, sans-serif")
            .AddStyleAttribute(HtmlTextWriterStyle.FontSize, "x-large")
            .AddStyleAttribute(HtmlTextWriterStyle.FontWeight, "bolder")
            .AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "center")
            .AddStyleAttribute(HtmlTextWriterStyle.Overflow, "hidden")
            .AddStyleAttribute(HtmlTextWriterStyle.Position, "absolute")
            .AddStyleAttribute(HtmlTextWriterStyle.Width, m_width.ToString & "pt")
            .AddStyleAttribute(HtmlTextWriterStyle.Height, m_height.ToString & "pt")
            .RenderBeginTag(HtmlTextWriterTag.Div)
            .AddStyleAttribute(HtmlTextWriterStyle.Width, "100%")
            .AddStyleAttribute(HtmlTextWriterStyle.Height, "100%")
            .RenderBeginTag(HtmlTextWriterTag.Table)
            .RenderBeginTag(HtmlTextWriterTag.Tbody)
            .RenderBeginTag(HtmlTextWriterTag.Tr)
            .AddAttribute(HtmlTextWriterAttribute.Valign, "middle")
            .RenderBeginTag(HtmlTextWriterTag.Td)
            .WriteLine("Pivottable will appear here.")
            .RenderEndTag() ' td
            .RenderEndTag() ' tr
            .RenderEndTag() ' tbody
            .RenderEndTag() 'table
            .RenderEndTag() ' div
        End With
    End Sub
    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        If Me.DesignMode Then
            RenderDesignTimeUI(writer)
            Exit Sub
        End If

        RenderRunTimeUI(writer)
    End Sub

    Public Sub New()
        InitializePropertyDefaults()
    End Sub
End Class
